/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VistaImpuesto.java
 *
 * Created on 18-nov-2011, 21:50:40
 */
package Vistas;

import Beans.Impuesto;
import Controladores.MImpuesto;
import Imagenes.CtrlImagen;
import java.io.IOException;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Ethan Amador
 */
public class VistaImpuesto extends javax.swing.JFrame {

    /** Creates new form VistaImpuesto */
    
    MImpuesto Imp = new MImpuesto();
    Impuesto Im = new Impuesto();
    DefaultTableModel dlm = new DefaultTableModel();
    int indice=-1;
    int fila;
    
    public VistaImpuesto() {
        initComponents();
    }
    
    public VistaImpuesto(MImpuesto Imp) {
        initComponents();
        this.Imp=Imp;
        
        dlm.addColumn("Codigo");
        dlm.addColumn("Nombre");
        dlm.addColumn("Porcentaje");
         
        
        for(int x=0;x<Imp.getListImpuestos().size();x++){
            Vector<String> vi = new Vector<String>();        
            vi.add(Imp.getListImpuestos().get(x).getCodigo()+"");
            vi.add(Imp.getListImpuestos().get(x).getNombre());
            vi.add(Imp.getListImpuestos().get(x).getPorcentaje()+"%");
            
            dlm.addRow(vi);
    }
       }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new CtrlImagen("/Imagenes/a1.jpg");
        jPanelTransparente1 = new Imagenes.JPanelTransparente();
        jLbNombre = new javax.swing.JLabel();
        JTxtNombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTxtPorcentaje = new javax.swing.JTextField();
        jPanelTransparente5 = new Imagenes.JPanelTransparente();
        jBModificar = new javax.swing.JButton();
        jBAgregar = new javax.swing.JButton();
        jBEliminar = new javax.swing.JButton();
        jBCancelar = new javax.swing.JButton();
        jBSalir = new javax.swing.JButton();
        jPanelTransparente3 = new Imagenes.JPanelTransparente();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTImpuesto = new javax.swing.JTable();
        jBEliminarTodo = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Intefaz Control de Impuestos");

        jPanelTransparente1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Agregar Impuesto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N

        jLbNombre.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLbNombre.setForeground(new java.awt.Color(255, 255, 255));
        jLbNombre.setText("Nombre");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Porcentaje");

        javax.swing.GroupLayout jPanelTransparente1Layout = new javax.swing.GroupLayout(jPanelTransparente1);
        jPanelTransparente1.setLayout(jPanelTransparente1Layout);
        jPanelTransparente1Layout.setHorizontalGroup(
            jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                        .addComponent(jLbNombre)
                        .addGap(27, 27, 27)
                        .addComponent(JTxtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE))
                    .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTxtPorcentaje, javax.swing.GroupLayout.DEFAULT_SIZE, 176, Short.MAX_VALUE)))
                .addGap(20, 20, 20))
        );
        jPanelTransparente1Layout.setVerticalGroup(
            jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente1Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLbNombre)
                    .addComponent(JTxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanelTransparente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTxtPorcentaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        ListSelectionModel lsm = jTImpuesto.getSelectionModel();
        lsm.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel ls=(ListSelectionModel )e.getSource();
                    if(ls.isSelectionEmpty()){
                        fila=-1;
                        jBModificar.setEnabled(false);
                    }else{
                        fila=ls.getMinSelectionIndex();
                        jBModificar.setEnabled(true);
                    }
                }catch(Exception z){
                }
            }
        });
        jBModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/edit.png"))); // NOI18N
        jBModificar.setText("MODIFICAR");
        jBModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBModificarActionPerformed(evt);
            }
        });

        jBAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/add.png"))); // NOI18N
        jBAgregar.setText("AGREGAR");
        jBAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAgregarActionPerformed(evt);
            }
        });

        ListSelectionModel lsms = jTImpuesto.getSelectionModel();
        lsms.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel lss=(ListSelectionModel )e.getSource();
                    if(lss.isSelectionEmpty()){
                        fila=-1;
                        jBEliminar.setEnabled(false);
                    }else{
                        fila=lss.getMinSelectionIndex();
                        jBEliminar.setEnabled(true);
                    }
                }catch(Exception z){
                }
            }
        });
        jBEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/stop.png"))); // NOI18N
        jBEliminar.setText("ELIMINAR");
        jBEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEliminarActionPerformed(evt);
            }
        });

        jBCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/burn.png"))); // NOI18N
        jBCancelar.setText("CANCELAR");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jBSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Desktop 2.png"))); // NOI18N
        jBSalir.setText("SALIR");
        jBSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelTransparente5Layout = new javax.swing.GroupLayout(jPanelTransparente5);
        jPanelTransparente5.setLayout(jPanelTransparente5Layout);
        jPanelTransparente5Layout.setHorizontalGroup(
            jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jBAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        jPanelTransparente5Layout.setVerticalGroup(
            jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jBAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jBModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelTransparente3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "IMPUESTOS", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(255, 255, 255))); // NOI18N

        jTImpuesto.setModel(dlm);
        jScrollPane1.setViewportView(jTImpuesto);

        jBEliminarTodo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/stop.png"))); // NOI18N
        jBEliminarTodo.setText("ELIMINAR TODO");
        jBEliminarTodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEliminarTodoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelTransparente3Layout = new javax.swing.GroupLayout(jPanelTransparente3);
        jPanelTransparente3.setLayout(jPanelTransparente3Layout);
        jPanelTransparente3Layout.setHorizontalGroup(
            jPanelTransparente3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBEliminarTodo, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanelTransparente3Layout.setVerticalGroup(
            jPanelTransparente3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jBEliminarTodo, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanelTransparente1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addComponent(jPanelTransparente5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jPanelTransparente3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelTransparente3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanelTransparente1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanelTransparente5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jMenu1.setText("Operaciones");
        jMenu1.add(jSeparator1);

        jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/exit.png"))); // NOI18N
        jMenuItem8.setText("Salir");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edicion");

        jMenuItem1.setText("Copiar");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed

        // Salir         this.dispose();     }//GEN-LAST:event_jMenuItem8ActionPerformed
            this.dispose();
    }
        private void jBAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAgregarActionPerformed
        //AGREGAR
            
            Impuesto Im = new Impuesto();
            Im.setCodigo(Imp.GenerarCodigo());
            Im.setNombre(JTxtNombre.getText());
            Im.setPorcentaje(Double.parseDouble(jTxtPorcentaje.getText()));
            Imp.Registrar(Im);
            AgregarLineaTabla(Imp.getListImpuestos());
            this.Actualizar();
            
            
    }//GEN-LAST:event_jBAgregarActionPerformed

    private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
        // TODO add your handling code here:
        this.Actualizar();
        this.BorrarCampos();
    }//GEN-LAST:event_jBCancelarActionPerformed

    private void jBModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBModificarActionPerformed
        // MODIFICAR IMPUESTO
        if(jBModificar.getText().equals("MODIFICAR")){
            indice = jTImpuesto.getSelectedRow();
             Im = Imp.getListImpuestos().get(indice);
            JTxtNombre.setText(Im.getNombre());
            JTxtNombre.requestFocus();
            jTxtPorcentaje.setText(Im.getPorcentaje()+"");
            jBModificar.setText("GUARDAR");
            ImageIcon[] img_Btns = new ImageIcon[8];
            img_Btns[0] = new ImageIcon(getClass().getResource("/Imagenes/Floppy.png"));
            jBModificar.setIcon(img_Btns[0]);

        }else{
            Impuesto im= new Impuesto(Im.getCodigo(),JTxtNombre.getText(),Double.parseDouble(jTxtPorcentaje.getText()));
            Imp.getListImpuestos().set(indice, im);
            Imp.Modificar(indice, Im.getCodigo(), im);
            indice=-1;
            Im=new Impuesto();
            
            Actualizar();
        }
    }//GEN-LAST:event_jBModificarActionPerformed

    private void jBEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEliminarActionPerformed
        // ELIMINAR
        Impuesto im = Imp.getListImpuestos().get(jTImpuesto.getSelectedRow());
        Imp.Eliminar(im.getCodigo());
        this.Actualizar();
    }//GEN-LAST:event_jBEliminarActionPerformed

    private void jBSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalirActionPerformed
        // SALIR
        this.dispose();
    }//GEN-LAST:event_jBSalirActionPerformed

    private void jBEliminarTodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEliminarTodoActionPerformed
        // BORRAR TODOS LOS IMPUESTOS
         int pregunta = JOptionPane.showConfirmDialog(null,"¿Seguro"
                + " que desea eliminar todas las categorias?","Eliminar",JOptionPane.YES_NO_OPTION);
        if(pregunta==0){
            this.cleanTabla();
            this.borrarLista();
        }
    }//GEN-LAST:event_jBEliminarTodoActionPerformed

            /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VistaImpuesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VistaImpuesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VistaImpuesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VistaImpuesto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VistaImpuesto().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField JTxtNombre;
    private javax.swing.JButton jBAgregar;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JButton jBEliminar;
    private javax.swing.JButton jBEliminarTodo;
    private javax.swing.JButton jBModificar;
    private javax.swing.JButton jBSalir;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLbNombre;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private Imagenes.JPanelTransparente jPanelTransparente1;
    private Imagenes.JPanelTransparente jPanelTransparente3;
    private Imagenes.JPanelTransparente jPanelTransparente5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTable jTImpuesto;
    private javax.swing.JTextField jTxtPorcentaje;
    // End of variables declaration//GEN-END:variables

    private void AgregarLineaTabla(List<Impuesto> listImpuestos) {
        this.cleanTabla();
        
        for(int x=0;x<listImpuestos.size();x++){
            Vector<String> v = new Vector<String>();
            v.add(listImpuestos.get(x).getNombre());
            v.add(listImpuestos.get(x).getCodigo()+"");
            v.add(listImpuestos.get(x).getPorcentaje()+"");
            dlm.addRow(v);
        }
              
    }
    
    public void cleanTabla(){

        dlm=(DefaultTableModel) jTImpuesto.getModel();
        int x=dlm.getRowCount();
        for(int i=-1;i<(x-1);i++){
              dlm.removeRow(0);
       }
      
  }
    
     private void Actualizar() {
        this.dispose();
        VistaImpuesto Vi = new VistaImpuesto(Imp);
        Vi.setLocationRelativeTo(null);
        Vi.setVisible(true);
    }

    private void BorrarCampos() {
        
        this.JTxtNombre.setText("");
        this.jTxtPorcentaje.setText("");
    }

    private void borrarLista() {
        Imp.getListImpuestos().clear();
        try {
            Imp.grabar();
        } catch (IOException ex) {
            Logger.getLogger(VistaImpuesto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
